/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package casino;

import java.util.Iterator;
import java.util.List;

/**
 * Class used to computer mean and standard deviation of Integer values in a List.
 * 
 * @author  amaghfur
 * @since   1.0
 */
public class InterStatistics {
    
    /**
     * Calculate the mean of the given values.
     * 
     * @param   values  list of values
     * @return  mean of values
     */
    public static double mean(List<Integer> values) {
        double s = 0;
        Iterator<Integer> itValues = values.iterator();
        while(itValues.hasNext() == true) {
            s = s + (int)itValues.next();
        }
        return s / values.size();
    }
    
    /**
     * Calculate the standard deviation of the given values.
     * 
     * @param   values  list of values
     * @return  standard deviation of values 
     */
    public static double stdev(List<Integer> values) {
        double mean = mean(values);
        double s = 0;
        Iterator<Integer> itValues = values.iterator();
        while(itValues.hasNext() == true) {
            double d = (int)itValues.next() - mean;
            s = s + d*d;
        }
        double variance = s / (values.size() - 1);
        return Math.sqrt(variance);
    }
    
}
